//
//  LYAppDelegate.m
//  LYWeiBo
//
//  Created by 老岳 on 13-9-27.
//  Copyright (c) 2013年 LY. All rights reserved.
//

#import "LYAppDelegate.h"
#import "LYLeftViewController.h"
#import "LYRightViewController.h"

#import "LYNavigationController.h"
#import "LYTabBarController.h"

#import "LYHomeViewController.h"
#import "LYMessageViewController.h"
#import "LYMeViewController.h"
#import "LYSquareViewController.h"
#import "LYMoreViewController.h"

@implementation LYAppDelegate
@synthesize mainDrawerController = _mainDrawerController;

- (void)dealloc
{
    [_window release];
    [_mainDrawerController release];
    [super dealloc];
}

//初始化 rootViewController
- (void)initRootViewController
{
    //中
    LYTabBarController *tabBarController = [self initTabBarController];
    //左
    LYLeftViewController *leftVC = [[LYLeftViewController new] autorelease];
    LYNavigationController *leftNV = [[[LYNavigationController alloc] initWithRootViewController:leftVC] autorelease];
    //右
    LYRightViewController *rightVC = [[LYRightViewController new] autorelease];
    LYNavigationController *rightNV = [[[LYNavigationController alloc] initWithRootViewController:rightVC] autorelease];
    
    self.mainDrawerController = [[[MMDrawerController alloc] initWithCenterViewController:tabBarController
                                                                 leftDrawerViewController:leftNV
                                                                rightDrawerViewController:rightNV] autorelease];
    [self.mainDrawerController setMaximumLeftDrawerWidth:LeftVC_Width];
    [self.mainDrawerController setMaximumRightDrawerWidth:RightVC_Width];
    [self.mainDrawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.mainDrawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    
    self.window.rootViewController = self.mainDrawerController;
}

//初始化 tabBarController
- (LYTabBarController *)initTabBarController
{
    LYHomeViewController *homeVC = [[LYHomeViewController new] autorelease];
    LYNavigationController *homeNV = [[[LYNavigationController alloc] initWithRootViewController:homeVC] autorelease]; 
    
    LYMessageViewController *messageVC = [[LYMessageViewController new] autorelease];
    LYNavigationController *messageNV = [[[LYNavigationController alloc] initWithRootViewController:messageVC] autorelease];
    
    LYMeViewController *meVC = [[LYMeViewController new] autorelease];
    LYNavigationController *meNV = [[[LYNavigationController alloc] initWithRootViewController:meVC] autorelease];
    
    LYSquareViewController *squareVC = [[LYSquareViewController new] autorelease];
    LYNavigationController *squareNV = [[[LYNavigationController alloc] initWithRootViewController:squareVC] autorelease];
    
    LYMoreViewController *moreVC = [[LYMoreViewController new] autorelease];
    LYNavigationController *moreNV = [[[LYNavigationController alloc] initWithRootViewController:moreVC] autorelease];
    
    LYTabBarController *tabBarController = [[LYTabBarController new] autorelease];
    tabBarController.viewControllers = [NSArray arrayWithObjects:homeNV,messageNV,meNV,squareNV,moreNV, nil];
    
    return tabBarController;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [self initRootViewController];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    
}

@end
